package day05;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import day05.Denglulei.BackgroundPanel;

public class Caidanlei extends JFrame {
	Container ct;//创建一个容器
	BackgroundPanel bgp;//创建背景画板
	JLabel j1=new JLabel("国家一级人才考试系统");
	JButton j2=new JButton("开始");
	JButton j3=new JButton("分数");
	JButton j4=new JButton("考试规则");
	JButton j5=new JButton("离开");
	JLabel j6=new JLabel("我是文本标签二号");
	JLabel j7=new JLabel("国家人才院--侵权必究");
	private ClientContext clientcontext;
	public ClientContext getClientcontext() {
		return clientcontext;
	}
	public void setClientcontext(ClientContext clientcontext) {
		this.clientcontext = clientcontext;
	}
	
	
	Caidanlei(){
		init();
		this.setTitle("菜单就完事了");
		this.setSize(800, 600);
		this.setResizable(false);
	    this.setLocationRelativeTo(null);
	    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
//	    this.setVisible(true);
	    start();
	 
	}
	public void init() {
		ct=this.getContentPane();
		bgp=new BackgroundPanel((new ImageIcon("风景2.jpg")).getImage());
        this.setLayout(null);
        bgp.setBounds(0,0,800,600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//標題
        j1.setBounds(100, 30, 700, 60);
        j1.setFont(new Font("宋体",Font.BOLD,60));
        j1.setForeground(Color.CYAN);
		//开始按鈕
        j2.setBounds(60, 200, 150, 150);
        j2.setFont(new Font("宋体",Font.BOLD,25));
		//分数按鈕
        j3.setBounds(230, 200, 150, 150);
        j3.setFont(new Font("宋体",Font.BOLD,25));
		//考试规则按鈕  
        j4.setBounds(400, 200, 150, 150);
        j4.setFont(new Font("宋体",Font.BOLD,25));
		//离开按鈕    
        j5.setBounds(570, 200, 150, 150);
        j5.setFont(new Font("宋体",Font.BOLD,25));
        //文本标签
        j6.setBounds(280, 130, 250,25);
        j6.setFont(new Font("楷体",Font.BOLD,25));
        j6.setForeground(new Color(250,250,210));
        //右下角文本标签
        j7.setBounds(550, 500, 250, 20);
        j7.setFont(new Font("楷体",Font.BOLD,20));
        j7.setForeground(Color.CYAN);
        
        this.add(j1);
        this.add(j2);
        this.add(j3);
        this.add(j4);
        this.add(j5);
        this.add(j6);
        this.add(j7);  
        ct.add(bgp,new Integer(Integer.MIN_VALUE));
	}
	public void start() {
		Mylistener  ml=new Mylistener();
		j2.addActionListener(ml);
		j3.addActionListener(ml);
		j4.addActionListener(ml);
		j5.addActionListener(ml);
	}
	public void shutdown() {
		this.dispose();
	}
	
	private class  Mylistener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			String Buttonname=e.getActionCommand();
			if(Buttonname.equals("开始")) {
				clientcontext.showthree();
//				clientcontext.setTime();
				shutdown();
			}else if(Buttonname.equals("分数")){
				
				
				
			}else if(Buttonname.equals("考试规则")) {
				Shujuku sj=new Shujuku();
				JOptionPane.showMessageDialog(j4, sj.getRulee());
				
				
			}else if(Buttonname.equals("离开")) {
				shutdown();
			}
		}


	}

	public void updateView(String username) {
		j6.setText(username + "同学欢迎你！");
		
	}
    class BackgroundPanel extends JPanel{
       	Image im;
       	public BackgroundPanel(Image im)
       	{
       		this.im=im;
       		this.setOpaque(true);
       	}
       	
       	public void paintComponent(Graphics g)
       	{
       		super.paintComponents(g);
       		g.drawImage(im,0,0,this.getWidth(),this.getHeight(),this);
       		
       	}

       }

}
